import 'package:flutter/material.dart';
import 'package:flutter_demo/ui/pages/comic/home/index.dart';
import 'package:get/get.dart';

import 'index.dart';

class ComicPage extends StatefulWidget {
  static const routeName = "/ComicPage";
  const ComicPage({Key? key}) : super(key: key);
  @override
  State<ComicPage> createState() => _ComicPageState();
}

class _ComicPageState extends State<ComicPage>
    with AutomaticKeepAliveClientMixin {
  int _currentIndex = 0;
  @override
  bool get wantKeepAlive => true;
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return GetBuilder<ComicController>(
      init: ComicController(),
      id: "comic",
      builder: (_) {
        return Scaffold(
            extendBodyBehindAppBar: true,
            body: HomePage(),
            bottomNavigationBar: _buildBottomNavigationBar());
      },
    );
  }

  BottomNavigationBar _buildBottomNavigationBar() {
    return BottomNavigationBar(
      onTap: _onTabTapped,
      items: const <BottomNavigationBarItem>[
        BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
        BottomNavigationBarItem(icon: Icon(Icons.library_books), label: "书架"),
        BottomNavigationBarItem(icon: Icon(Icons.person_outline), label: "我的"),
      ],
      type: BottomNavigationBarType.fixed,
      iconSize: 20,
      selectedFontSize: 12,
      unselectedFontSize: 10,
      currentIndex: _currentIndex,
    );
  }

  _onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}
